//
//  AnquanViewController.m
//  盘盈贷1.2
//
//  Created by iOS on 15/3/13.
//  Copyright (c) 2015年 iOS. All rights reserved.
//

#import "AnquanViewController.h"
#import "EmailViewController.h"
#import "ShenfenrenzhengViewController.h"
#import "TeleViewController.h"
#import "QuestionViewController.h"
#import "YinhangViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "ChangeLoginViewController.h"
#import "ChangepayViewController.h"
@interface AnquanViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *myself;
@property (nonatomic, retain) NSMutableArray *shezhi;
@property (nonatomic, retain) NSMutableArray *guanyu;
@property (nonatomic, retain) NSMutableArray *question;
@property (nonatomic, retain) NSMutableArray *first;
@property (nonatomic, retain)NSMutableArray *second;
@property (nonatomic, retain)NSMutableArray *third;
@property (nonatomic, retain)NSMutableArray *fouth;
@property (nonatomic, retain)NSDictionary *dic;
@property (nonatomic, retain)NSDictionary *user;


@end

@implementation AnquanViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
       self.title = @"账户安全";
        self.myself = [NSMutableArray arrayWithObjects:@"身份认证", nil];
        self.shezhi = [NSMutableArray arrayWithObjects:@"邮箱验证", @"手机认证", nil];
        self.guanyu = [NSMutableArray arrayWithObjects:@"银行卡绑定", nil];
        self.question = [NSMutableArray arrayWithObjects:@"安全问题", @"登陆密码", @"交易密码", nil];
        
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 1.23) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.view addSubview:self.tableView];
    [self.tableView release];
    UIImage *image = [UIImage imageNamed:@"safe_idcard_yes.png"];
     self.first = [NSMutableArray arrayWithObjects:image, nil];
    UIImage *image1 = [UIImage imageNamed:@"safe_email_yes.png"];
    UIImage *image2= [UIImage imageNamed:@"safe_phone_yes.png"];
    self.second = [NSMutableArray arrayWithObjects: image1, image2, nil];
    UIImage *image3 = [UIImage imageNamed:@"safe_bankcard_yes.png"];
    self.third = [NSMutableArray arrayWithObjects:image3, nil];
    UIImage *image4 = [UIImage imageNamed:@"safe_question_yes.png"];
    UIImage *image5 = [UIImage imageNamed:@"safe_password_yes.png"];
    UIImage *image6 = [UIImage imageNamed:@"safe_trade_password_yes.png"];
    self.fouth = [NSMutableArray arrayWithObjects:image4, image5, image6, nil];
    
    [self HttpResponseObject];
   

}
- (void)HttpResponseObject
{
    NSString *str = [NSString stringWithFormat:@"http://www.cloudpeng.com:8102/audit/SecurityAudit?username=%@", self.strname];
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        self.dic = responseObject;
        self.user = [responseObject objectForKey:@"UserDetail"];
       
        [self.tableView reloadData];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"~~~~~~~%@",error);
    }];
  
    
}
//设置tableview 每个分区(section)显示多少行(row)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    switch (section) {
        case 0:
            return self.myself.count;
            break;
        case 1:
            return self.shezhi.count;
            break;
        case 2:
            return self.guanyu.count;
            break;
        default:
            return self.question.count;
            break;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 10;
    } else if (section == 4){
        return 25.0;
    } else {
        return 12.0;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"1"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"1"];
        }
        cell.textLabel.text = self.myself[indexPath.row];
        cell.textLabel.textAlignment = NSTextAlignmentLeft;
        cell.imageView.image = self.first[indexPath.row];
                if (indexPath.row == 0) {
                    NSString *idnumber = [NSString stringWithFormat:@"%@", [self.dic objectForKey:@"IsIdentityAudit"]];
                    if ([idnumber isEqual:@"1"]) {
//                        NSString *idcard = [self.user objectForKey:@"IDCardNumber"];
//                        NSString *str1 = [idcard substringWithRange:NSMakeRange(4,11)];
//                        NSString *str2 = [idcard stringByReplacingOccurrencesOfString:str1 withString:@"***********"];
                        cell.detailTextLabel.text = @"身份证号已认证";
                        cell.detailTextLabel.textAlignment = NSTextAlignmentCenter;
                        cell.accessoryType = UITableViewCellAccessoryNone;
        
                    } else {
                        cell.detailTextLabel.text = @"身份证号未认证";
                        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                        
                    }
                    
                }


        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        
        
    } else if (indexPath.section == 1) {
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"2"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"2"];
        }
        cell.textLabel.text = self.shezhi [indexPath.row];
        cell.imageView.image = self.second[indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                if (indexPath.row == 0) {
                    NSString *email = [NSString stringWithFormat:@"%@", [self.dic objectForKey:@"IsEmailAudit"]];
                    if ([email isEqual:@"1"]) {
        
                        cell.detailTextLabel.text = [self.user objectForKey:@"Email"];
                        cell.detailTextLabel.textAlignment = NSTextAlignmentCenter;
        
                    } else {
                        cell.detailTextLabel.text = @"您的邮箱未注册";
        
                    }
                   
                          }
                if (indexPath.row == 1) {
                    NSString *tele = [NSString stringWithFormat:@"%@", [self.dic objectForKey:@"IsPhoneAudit"]];
                    if ([tele isEqual:@"1"]) {
        
        
//                        NSString *tele = [self.user objectForKey:@"Phone"];
//                        NSString *tele1 = [tele substringWithRange:NSMakeRange(3,4)];
//                        NSString *tele2 = [tele stringByReplacingOccurrencesOfString:tele1 withString:@"****"];
                        cell.detailTextLabel.text = @"手机号已绑定";
                         cell.detailTextLabel.textAlignment = NSTextAlignmentCenter;
        
                    } else {
                        cell.detailTextLabel.text = @"未绑定手机号";
                        
                    }
                    
                }



        return cell;
        
    } else if (indexPath.section == 2){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"3"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"3"];
        }
        cell.textLabel.text = self.guanyu [indexPath.row];
        cell.imageView.image = self.third [indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                if (indexPath.row == 0) {
        
                    NSString *bank = [NSString stringWithFormat:@"%@", [self.dic objectForKey:@"HasBanks"]];
                    if ([bank isEqual:@"1"]) {
        
                        cell.detailTextLabel.text = @"您已绑定银行卡";
                    } else {
                        cell.detailTextLabel.text = @"您必须绑定银行卡方可提现";
        
                    }
                   
                }

        return cell;
    }else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"3"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"3"];
        }
        cell.textLabel.text = self.question [indexPath.row];
        cell.imageView.image = self.fouth [indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                if (indexPath.row == 0) {
                    NSString *answer = [NSString stringWithFormat:@"%@", [self.dic objectForKey:@"HasAnswer"]];
                    if ([answer isEqual:@"1"]) {
        
                        cell.detailTextLabel.text = @"您已设置安全问题";
                    } else {
                         cell.detailTextLabel.text = @"您未设置安全问题";
                        
                    }
          }
                if (indexPath.row == 1) {
                    cell.detailTextLabel.text = @"经常性修改登陆密码能有效保护您的账户安全";
        
        
                }
                if (indexPath.row == 2){
                    cell.detailTextLabel.text = @"您必须设置交易密码用于投资,提现";
                }
        return cell;
    }
    

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 6;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (indexPath.section == 0) {
            NSString *idnumber = [NSString stringWithFormat:@"%@", [self.dic objectForKey:@"IsIdentityAudit"]];
            if ([idnumber isEqual:@"1"]) {
            } else{
            ShenfenrenzhengViewController *shenfen = [[ShenfenrenzhengViewController alloc] init];
            UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
            backItem.title=@"返回";
            //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
            self.navigationItem.backBarButtonItem = backItem;
            [backItem release];
                shenfen.name = self.strname;
            }
            
        } else if (indexPath.section == 1){
            if (indexPath.row == 0) {
                EmailViewController *email = [[EmailViewController alloc] init];
                UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
                backItem.title=@"返回";
                //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
                self.navigationItem.backBarButtonItem = backItem;
                [backItem release];
                email.name = self.strname;
                [self.navigationController pushViewController:email animated:YES];
                [email release];
            }
            if (indexPath.row == 1) {
                                TeleViewController *tele = [[TeleViewController alloc] init];
                            UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
                            backItem.title=@"返回";
                            //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
                            self.navigationItem.backBarButtonItem = backItem;
                            [backItem release];
                            tele.name = self.strname;
                                [self.navigationController pushViewController:tele animated:YES];
            }
            
        } else if (indexPath.section == 2) {
            YinhangViewController *yinhang = [[YinhangViewController alloc] init];
                        UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
                        backItem.title=@"返回";
                        //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
                        self.navigationItem.backBarButtonItem = backItem;
                        [backItem release];
                            [self.navigationController pushViewController:yinhang animated:YES];
        }else if (indexPath.section == 3){
            if (indexPath.row == 0) {
                QuestionViewController *question = [[QuestionViewController alloc] init];
                UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
                backItem.title=@"返回";
                //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
                self.navigationItem.backBarButtonItem = backItem;
                [backItem release];
                [self.navigationController pushViewController:question animated:YES];
            } else if (indexPath.row == 1){
                                ChangeLoginViewController *login = [[ChangeLoginViewController alloc] init];
                                UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
                                backItem.title=@"返回";
                                //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
                                self.navigationItem.backBarButtonItem = backItem;
                                [backItem release];
                                login.name = self.strname;
                                [self.navigationController pushViewController:login animated:YES];
                
            }else if (indexPath.row == 2){
                ChangepayViewController *pay = [[ChangepayViewController alloc] init];
                UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
                backItem.title=@"返回";
                //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
                self.navigationItem.backBarButtonItem = backItem;
                [backItem release];
                pay.name = self.strname;
                [self.navigationController pushViewController:pay animated:YES];
            }
        }else {
                ChangepayViewController *pay = [[ChangepayViewController alloc] init];
                                UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
                                backItem.title=@"返回";
                                //            backItem.tintColor=[UIColor colorWithRed:129/255.0 green:129/255.0  blue:129/255.0 alpha:1.0];
                                self.navigationItem.backBarButtonItem = backItem;
                                [backItem release];
                                pay.name = self.strname;
                                [self.navigationController pushViewController:pay animated:YES];
            }

    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
